Add the concept of a dedicated Router and custom Routes #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This introduces the concept of a
Router
with app-providedRoute
implementations that determine:location
matches theRoute
location
url should be routed through in-app navigationlocation
url won't be navigated through in-app navigation (such as routing to an external browser, openingmailto:
links, etc).The
Route
interface looks like this:Before performing an in-app navigation visit,
TurboNavigator
routes thelocation
url through the approuter
. Therouter
loops over each registeredRoute
until it gets a match (the order of the registered routes determine in what order they're processed). The matchedRoute
must return one of either:RouteResult.NAVIGATE
: Informs the navigator to continue performing the in-app navigation visit.RouteResult.STOP
: Informs the navigator to stop the in-app navigation visit. TheRoute
can provide its own custom behavior, such as opening an external browser.There are three built-in Routes that can be used by applications
AppNavigationRoute
: Allows locations urls on the same domain asHotwire.appUrl
to navigate within the app.BrowserRoute
: Allows location urls on a different domain fromHotwire.appUrl
to stop in-app navigation and route the url to an external browser.BrowserTabRoute
: Allows location urls on a different domain asHotwire.appUrl
to stop in-app navigation and route the url to a browser Custom Tab.By default,
AppNavigationRoute
andBrowserRoute
are registered. The routes that an application uses can be configured by callingHotwire.registerRoutes(routes)
. Applications can create their ownRoute
implementations by implementing theRoute
interface and registering the route.